#!/bin/bash

yes y | head -1 | yum install expect
mkdir /lnmp
cd /lnmp
wget http://soft.vpser.net/lnmp/lnmp1.9.tar.gz -cO lnmp1.9.tar.gz && tar zxf lnmp1.9.tar.gz && cd lnmp1.9 && LNMP_Auto="y" DBSelect="4" Bin="n" DB_Root_Password="iCWPCbWkBinAdfk7" InstallInnodb="y" PHPSelect="10" SelectMalloc="1" ./install.sh lnmp

mkdir -p /lnmp/wwwlogs
mkdir -p /lnmp/wwwroot/vccms
cd /lnmp/wwwroot/vccms
wget http://vc-cms.cloud.coyuns.com.cn/latest.zip
unzip latest.zip
chown -R www:www /lnmp/wwwroot/vccms
chown -R www:www /lnmp/wwwlogs
cp /lnmp/wwwroot/vccms/install/swoole_loader74.so /usr/local/php/lib/php/extensions/no-debug-non-zts-20190902
cp -rf /lnmp/wwwroot/vccms/install/lnmp/php.ini /usr/local/php/etc
cp -rf /lnmp/wwwroot/vccms/install/lnmp/.env /lnmp/wwwroot/vccms
cp -rf /lnmp/wwwroot/vccms/install/lnmp/vccms.conf /usr/local/nginx/conf/vhost
sed -i "s/    server_name 域名;/    server_name $1;/" /usr/local/nginx/conf/vhost/vccms.conf
cp -rf /lnmp/wwwroot/vccms/install/lnmp/fastcgi.conf /usr/local/nginx/conf
cp -rf /lnmp/wwwroot/vccms/install/lnmp/nginx.conf /usr/local/nginx/conf
service nginx start
service php-fpm restart
service nginx restart

/usr/bin/expect << EOF
spawn mysql -uroot -piCWPCbWkBinAdfk7
expect "mysql>"
send "create database vccmsdb;\r"
expect "mysql>"
send "use vccmsdb;\r"
expect "mysql>"
send "set names utf8mb4;\r"
expect "mysql>"
send "source /lnmp/wwwroot/vccms/install/install.sql;\r"
expect eof
exit
EOF